import {defineStore} from 'pinia';
import {useFrendsStore} from './frends';
import api from '@/api';

export const useUserStore = defineStore({
    id: 'user',
    state: function () {
        return {
            name: '行政服务'
        };
    },
    actions: {
        updateName(name: string) {
            this.name = name;
        },
        // 使用 async await 获取异步请求后数据
        async login(account: string, password: string) {
            this.updateName('行政服务前端');
            const {data} = await api.login(account, password);
            const appStore = useFrendsStore();
            appStore.setData(data);
            return data;
        }
    },
    // getters为state响应式添加需要进行再运算的数值
    getters: {
        fullName: (state) => {
            return state.name + '训练营';
        }
    }
});
